package cn.juque.common.exception;

import cn.juque.common.constants.BaseMessageEnum;
import cn.juque.common.constants.MessageEnum;
import lombok.Data;

/**
 * 应用级异常,可控(业务人员误操作产生的异常,如用户不存在、密码错误、用户名已经存在等)
 *
 * @author nuoka
 */
@Data
public class AppException extends RuntimeException {

    /**
     * 异常码
     */
    private final String code;

    public AppException() {
        this.code = MessageEnum.SYSTEM_ERROR.getCode();
    }

    public AppException(Throwable cause) {
        super(cause);
        this.code = MessageEnum.SYSTEM_ERROR.getCode();
    }

    public AppException(BaseMessageEnum messageEnum) {
        this(messageEnum.getCode(), messageEnum.getMsg());
    }

    public AppException(String message, Throwable cause) {
        super(message, cause);
        this.code = MessageEnum.SYSTEM_ERROR.getCode();
    }

    public AppException(String message) {
        super(message);
        this.code = MessageEnum.SYSTEM_ERROR.getCode();
    }

    public AppException(String code, String message) {
        super(message);
        this.code = code;
    }
}
